//
//  YDStatusRetweetView.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/13.
//  Copyright © 2016年 iitcast. All rights reserved.
//  转发微博 用到的图片都是自定义类中的图片 里面的cell更新就可以 外界不用再管

import UIKit
import SnapKit


class YDStatusRetweetView: UIView {
    
//    记录转发微博的底部约束
    var retweetedViewBottomConstraint:Constraint?
    
    var statusViewModel:YDStatusViewModel?{
        didSet{
        
            //        didSet中给属性重新赋值
            messageLable.attributedText = statusViewModel?.retweetAttr
//            卸载约束
            retweetedViewBottomConstraint?.uninstall()
            
//            判断 有配图
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0{
//                赋值  自定义图片的数组属性与 模型类中的真正请求到的数据匹配
                pictureImageView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
//                更新约束
                self.snp_makeConstraints { (make) -> Void in
                    retweetedViewBottomConstraint = make.bottom.equalTo(pictureImageView).offset(10).constraint
                }

//                显示配图
            pictureImageView.hidden = false
            
            }else{
//            没有配图
                
//              更新约束
                self.snp_makeConstraints { (make) -> Void in
                    retweetedViewBottomConstraint = make.bottom.equalTo(messageLable).offset(10).constraint
                }

//            隐藏配图
                pictureImageView.hidden = true
            
            }
        
        }
    
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    设置视图
    private func setUpUI(){
        backgroundColor = RGB(237,green: 237,blue: 237)
//    添加控件
        addSubview(messageLable)
//       添加图片
        
        addSubview(pictureImageView)
//        添加约束
        messageLable.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
        }
        pictureImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(messageLable.snp_bottom).offset(10)
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.leading.equalTo((KSCREENW - 250)/2)
        }
        self.snp_makeConstraints { (make) -> Void in
            retweetedViewBottomConstraint = make.bottom.equalTo(pictureImageView).offset(10).constraint
        }

    }
//    懒加载控件
    private lazy var messageLable:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: KSCREENW - 20)
    
//    配图
    private lazy var pictureImageView :YDStatusPictureView = YDStatusPictureView()
    
}







